<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>系统常量管理列表</title>
<%@include file="/common/head.jsp" %>

<!-- 时间日期插件 -->
<link href="<%=request.getContextPath()%>/static/plugin/My97DatePicker/skin/default/datepicker.css" rel="stylesheet" >
<script src="<%=request.getContextPath()%>/static/plugin/My97DatePicker/WdatePicker.js"></script>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>系统常量管理</span>
        </div>
        <div id="toolbar" style="float: right"></div>
    </div>
    <div class="page-title-border"></div>
</div>

<div class="search-field">
    <span class="field-cont">
        <span class="field-cont-title">系统常量KEY</span>
        <input type="text" class="summer-input" id="sysKey"/>
    </span>
  
    <span class="field-cont">
        <span class="field-cont-title">系统常量VALUE</span>
        <input type="text" class="summer-input" id="sysValue"/>
    </span>
    
    <span class="field-btn-wrapper">
        <a id="search" class="btn btn-primary btn-icon wave distance-right"><i class="icon icon-search"></i></a>
        <a id="reset" class="btn btn-icon wave wave-dark"><i class="icon icon-refresh"></i></a>
    </span>
</div>

<div id="t-wrap">
    <table class="summer-datagrid" id="dataList">
        <col width="30%">
	    <col width="30%">
	    <col width="30%">
	    <col width="10%">
	    <thead>
		    <tr>
		        <th>系统常量KEY</th>
				<th>系统常量VALUE</th>
				<th>更新时间</th>
		        <th>操作</th>
		    </tr>
	    </thead>
    </table>
</div>

<script>
    
    var  permission = CommonUtil.getPermission('syssetting');
    
    $(function () {
        // 新建toobar
		$.funcbar({
			id: 'toolbar',
			type: 'toolbar',
			data: permission,
			permit: ['syssetting:initAdd'],
		});
        
        // 查询按钮
        $('#search').on('click', reloadTable);
        
        //重置按钮
        $('#reset').on('click', function () {
        	//重置文本框的值
        	$('#sysKey').val('');
        	$('#sysValue').val(''); 
        	reloadTable();
        });
        
        //新建
        $('#toolbar').on('click', 'a[data-permit="syssetting:initAdd"]', function() {
        	window.location.href = CONST_URL.INIT_ADD; 	  	
		});
        
        
       createTable();
        
        //查看
        $('#t-wrap').on('click', 'a[data-permit="syssetting:initView"]', function() {
        	var $this = $(this),
        	    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
        	window.location.href = CONST_URL.INIT_VIEW +"?id=" + id;
        });
       
        //编辑
        $('#t-wrap').on('click', 'a[data-permit="syssetting:initEdit"]', function() {
            var $this = $(this),
                id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
            window.location.href = CONST_URL.INIT_EDIT + '?id=' + id;
        });	
        
        //删除
		$('#t-wrap').on('click', 'a[data-permit="syssetting:delete"]', function() {
			var $this = $(this),
			    id = $this.closest('tr').find('td[data-field="id"]').attr('data-value');
			$.sdialog({
				type: 'confirm',
				msg: '您确定要删除选中的记录吗?',
				onConfirm: function(result) {
				    if (result) {
				    	$.sajax({
			                url : CONST_URL.DEL + "?ids=" + id,
			                onLoadSuccess : function() {
			                	 $.stip({
                	                type:'ok',//显示类型 有info、 ok、 danger
                	                text: '删除成功！'    
			                	});
			                	reloadTable();  
			                }
			            });
				    		
				    }	
				}
			});
		});
    });
    
    // 重新加载表格
	function reloadTable() {
		$('#dataList').datagrid('reload',{
            ajax: {
            	param: {
            		"sysKey": trimSpace($('#sysKey').val()),
                	"sysValue": trimSpace($('#sysValue').val())
            	}
            }
        });
	}
    
    //创建表格
    function createTable() {
    	$('#dataList').datagrid({
    		ajax: {
    			url: CONST_URL.LIST,
    			param: {
    				"sysKey": trimSpace($('#sysKey').val()),
                	"sysValue": trimSpace($('#sysValue').val())
            	}
    		},
    		columns: [
    		     {
    		    	 field: 'id',
    		    	 hidden: true
    		     },
    		     {
    		    	 field: 'sysKey'//,
    		    	 //render: function (rowData) {
    		    		// return '<a href="javascript:;" data-permit="syssetting:initView" class="link">'+ rowData.sysKey +'</a>';
    		    	 //}
    		     },
    		     {
    		    	 field: 'sysValue'
    		     },
    		     {
    		    	 field: 'sysUpdateTime'
    		     },
    		    {
    		    	 render: function (rowData) {
    		    		 return $.funcbar({
    		    			 data: permission,    //请求的数据
    		    			 type: 'text',     //类型
    		    			 display: 2,    //显示数量
    		    			 permit: ['syssetting:initEdit', 'syssetting:delete'] //需要的权限按钮
    		    		 });
    		    	 }
    		    }
    		          
    	    ]
    	});
    }
    
   
    
    //请求url
    var CONST_URL = {
   		LIST: basePath + '/sys/syssetting/list',
       	INIT_ADD: basePath + "/sys/syssetting/initAdd",
       	INIT_EDIT: basePath + "/sys/syssetting/initEdit",
       	DEL: basePath + "/sys/syssetting/delete",
       	INIT_VIEW: basePath + "/sys/syssetting/initView"
    };
    
</script>
</body>
</html>